set ns [new Simulator]
set qsize 20
set ta [open 2.dat w]
set tq [open 3.dat w]
$ns trace-all $ta
set nf [open 4.nam w]
$ns namtrace-all $nf

proc finish {} {
	global ns  ta tq  nf
	$ns flush-trace
	close $nf
	exec nam 4.nam &
	close $ta
	close $tq
	exit 0
}
set n0 [$ns node]
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0


set n1 [$ns node]
$ns simlex-link $n0 $n1


$ns queue-limit $n0 $n1 $qsize
$ns trace-queue $n0 $n1 $tq
set qmon [$ns monitor-queue $n0 $n1 0.1]
set fqsize [open "qs.dat" w]

proc record {} {
	global ns qmon fqsize
	set time  [$ns now]
	set qsize [$qmon set pkts_]
	puts $fqsize "$time $qsize"
	$qmon reset

$ns at [expr $time+1.0] "record"
}

 $ns at 0 "record"
$ns at 50.0 "finish"

$ns run